//
//  YHYDesignerPersonViewController.m
//  Home
//
//  Created by 杨泓晔 on 16/4/19.
//  Copyright © 2016年 LanJue. All rights reserved.
//

#import "YHYDesignerPersonViewController.h"
#import "YHYDesignerPTableViewCell.h"
#import "WSShopInfoNextView.h"
#import "YHYAddWorkViewController.h"

#import "YHYAddView.h"
#import "YHYAddViewTwo.h"
#import "DCPaymentView.h"
#import "WSCustomPickerView.h"
#import "YHYJobViewController.h"
#import "YHYStyleViewController.h"
#import "YHYSaySomthingViewController.h"
#import "YHYStyleViewController.h"
#import "YHYAddStudyViewController.h"
@interface YHYDesignerPersonViewController ()<UITableViewDataSource,UITableViewDelegate,YHYJobNumberArrDelegate,YHYStyleNumberArrDelegate,WSCustomPickerViewDelegate,WSShopInfoNextViewDelegate>{
     NSInteger index;
}
@property (nonatomic,retain)UITableView *myTableView;
@property (nonatomic,retain)NSMutableArray *array;
@property (nonatomic,retain)NSMutableArray *workArray;
@property (nonatomic,retain)NSMutableArray *studyArray;
@property (nonatomic,retain)NSString *price;
//选择器
@property (nonatomic, strong) WSCustomPickerView *customPicker;
@property (nonatomic,retain)NSString *ageStr;
@property (nonatomic,retain)NSMutableArray *jobArray;
@property (nonatomic,retain)NSMutableArray *styleArray;
@end

@implementation YHYDesignerPersonViewController
- (void)viewWillAppear:(BOOL)animated {
    
    self.navigationController.navigationBarHidden = NO;
    self.tabBarController.tabBar.hidden=YES;
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    self.title = @"个人信息";
    
}

-(void) viewWillDisappear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden=NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStylePlain target:self action:@selector(Back:)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    
    self.view.backgroundColor = LV;
    _jobArray = [NSMutableArray array];
    [self creatView];
   
    
}

- (void)creatView{
    _array = [NSMutableArray arrayWithObjects:@"我的职业",@"收取费用",@"擅长风格",@"服务城市",@"工作状态",@"工作年限",@"个人介绍",@"我的亮点", nil];
    _workArray = [NSMutableArray arrayWithObjects:@"蓝觉", nil];
    _studyArray = [NSMutableArray arrayWithObjects:@"清华大学", nil];
    self.myTableView = [UITableView new];
    
    [self.view addSubview:self.myTableView];
    self.myTableView.rowHeight = 50 * AUTO_HEIGHT;
    // self.myTableView.sectionFooterHeight = 10;
    [self.myTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.mas_equalTo(self.view);
        make.height.mas_equalTo(self.view);
        make.width.mas_equalTo(self.view);
        
    }];
    self.myTableView.rowHeight = ROWHEIGHT;
   // _myTableView.scrollEnabled = NO;
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    self.myTableView.backgroundColor = LV;
    //[self.myTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    [self.myTableView registerClass:[YHYDesignerPTableViewCell class] forCellReuseIdentifier:@"YHYDesignerPTableViewCell"];
    [[UITableViewHeaderFooterView appearance] setTintColor:LV];

    [_myTableView reloadData];

}

-(void)Back:(UIButton *) goback
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 4;
    }
    if (section == 1) {
        return 4;
    }
    if (section == 2) {
        return _workArray.count;
    }
    if (section == 3) {
        return _studyArray.count;
    }
    if (section == 4) {
        return 0;
    }
    
    return 0;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *str  = @"YHYDesignerPTableViewCell";
    YHYDesignerPTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:str];
    if (indexPath.section == 0) {
         cell.xmLabel.text = [_array objectAtIndex:indexPath.row];
        if (indexPath.row == 0) {
            if (_jobArray.count != 0) {
                cell.WXlabel.text = [NSString stringWithFormat:@"%ld",_jobArray.count];
            }
            else{
                cell.WXlabel.text = [NSString stringWithFormat:@"必填"];
            }

            
        }
        if (indexPath.row == 1) {
            if (self.price != nil) {
                 cell.WXlabel.text = self.price;
            }
            else{
                cell.WXlabel.text = [NSString stringWithFormat:@"必填"];
            }
           
            
        }
        if (indexPath.row == 2) {
            if (_styleArray.count != 0) {
                cell.WXlabel.text = [NSString stringWithFormat:@"%ld",_styleArray.count];
            }
            else{
                cell.WXlabel.text = [NSString stringWithFormat:@"必填"];
            }
            

        }
    }
    if (indexPath.section == 1) {
        cell.xmLabel.text = [_array objectAtIndex:indexPath.row + 4];
        if (indexPath.row == 1) {
            cell.WXlabel.text = self.ageStr;

        }
    }
    if (indexPath.section == 2) {
        cell.xmLabel.text = [_workArray objectAtIndex:indexPath.row];
   
 
}
    
    
    if (indexPath.section == 3) {
        cell.xmLabel.text = [_studyArray objectAtIndex:indexPath.row];
    }
   
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            //我的职业
            YHYJobViewController *job = [YHYJobViewController new];
            job.delegate = self;
            [self.navigationController pushViewController:job animated:YES];
            
        }
        if (indexPath.row == 1) {
//            收取费用
            DCPaymentView *payAlert = [[DCPaymentView alloc] init];
            payAlert.title = [NSString stringWithFormat:@"报酬"];
            [payAlert setTextFieldKeyBordToNum];
            payAlert.numOfContent = 4;
            [payAlert show];
            payAlert.completeHandle = ^(NSString *inputPwd) {
                
//                [self.model.rewardArr addObject:inputPwd];
                self.price = [NSString stringWithFormat:@"%@元", inputPwd];
                [_myTableView reloadData];
            };

        }
        if (indexPath.row == 2) {
//            擅长风格
            YHYStyleViewController *style = [YHYStyleViewController new];
            style.delegate = self;
            [self.navigationController pushViewController:style animated:YES];
//            index = 1;
//            self.customPicker = nil;
//            self.customPicker = [[WSCustomPickerView alloc] initWithFrame:[UIScreen mainScreen].bounds type:1];
//            self.customPicker.delegate = self;
//            [self.view addSubview:_customPicker];
//            [self.customPicker showPicker];
        }
    }

    if (indexPath.section == 1) {
        if (indexPath.row == 1) {
//            工作年限
            index = 1;
            self.customPicker = nil;
            self.customPicker = [[WSCustomPickerView alloc] initWithFrame:[UIScreen mainScreen].bounds type:1];
            self.customPicker.delegate = self;
            [self.view addSubview:_customPicker];
            [self.customPicker showPicker];
            
        }
        if (indexPath.row == 2) {
//            个人介绍
            YHYSaySomthingViewController *say = [YHYSaySomthingViewController new];
            [self.navigationController pushViewController:say
                                                 animated:YES];
        }
    }
}
//协议方法
//- (void)presentworkName:(NSString *)workName type:(NSInteger *)type{
//    //插入数据
//    [_workArray addObject:workName];
//    NSLog(@"%@",workName);
//    [_myTableView reloadData];
//}
//job协议
- (void)persentArray:(NSMutableArray *)keyArray{
    _jobArray = [NSMutableArray arrayWithArray:keyArray];
   // NSLog(@"%ld",_jobArray.count);
    [_myTableView reloadData];
}
- (void)persentStyleNumberArray:(NSMutableArray *)keyarray{
    _styleArray = [NSMutableArray arrayWithArray:keyarray];
    [_myTableView reloadData];
}
- (void)presentAddWorkName:(NSString *)workName{
    [_workArray addObject:workName];
    NSLog(@"%@",workName);
    [_myTableView reloadData];
}

#pragma mark - 选择器代理方法
- (void)sendAddressInfo:(NSString *)address {
    
    if (index == 1) {
        NSDateFormatter* formatter = [[NSDateFormatter alloc]init];
        [formatter setDateFormat:@"YYYY-MM-dd"];
        NSString *date = [formatter stringFromDate:[NSDate date]];
        date = [date substringToIndex:4];
        address = [address substringToIndex:4];
        NSInteger age = [date integerValue] - [address integerValue];
       // self.contentAry[index] = [NSString stringWithFormat:@"%ld", age];
        self.ageStr = [NSString stringWithFormat:@"age%ld", (long)age];
    }
    
    
    [self.myTableView reloadData];
}



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 5;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    if (section == 1) {
        
        return 15 * AUTO_HEIGHT;
    }
    
    if (section == 2) {
        return 65 * AUTO_HEIGHT;
    }
    if (section == 3) {
        return 65 * AUTO_HEIGHT;
    }
    if (section == 4) {
        return 65 * AUTO_HEIGHT;
    }
    
    return 15 * AUTO_HEIGHT;
}

//- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
//    
//    return 5;
//}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    if (section == 2) {
        YHYAddView *view = [[YHYAddView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 100 * AUTO_HEIGHT)];
       view.delegate = self;
        return view;
    }
    if (section == 3) {
        YHYAddViewTwo *view = [[YHYAddViewTwo alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 100 * AUTO_HEIGHT)];
        //view.delegate = self;
       
        return view;

    }

    if (section == 4) {
        WSShopInfoNextView *view = [[WSShopInfoNextView alloc] initWithFrame:CGRectMake(0, 40* AUTO_HEIGHT, SCREEN_WIDTH-88 *AUTO_WIDTH, 78/2 * AUTO_HEIGHT)];
        [view.button setTitle:@"保存" forState:UIControlStateNormal];
        view.button.titleLabel.font=[UIFont fontWithName:@"Arial" size:LOGINFONT *TEXTWEIGHT];
        view.delegate = self;
        return view;
    }
    return nil;
}
//协议
- (void)present{
   
    YHYAddWorkViewController *add = [YHYAddWorkViewController new];
    [self.navigationController pushViewController:add animated:YES];
    add.delegate = self;
}

- (void)nextAction{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)presentTwo{
//    YHYAddWorkViewController *add = [YHYAddWorkViewController new];
//    [self.navigationController pushViewController:add animated:YES];
    YHYAddStudyViewController *add = [YHYAddStudyViewController new];
    [self.navigationController pushViewController:add animated:YES];
//    add.delegate = self;
}

@end
